package com.ColonyCount;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Bitmap;
import android.util.Log;

import com.ColonyCount.Image.Histogram;
import com.ColonyCount.Image.Image8;
import com.ColonyCount.Image.ImageRegion;

public class ColonyCountHeap {
	
	static  Bitmap sourceBitmap;
    static Image8 lumaMap;
    static Bitmap lumaBitmap;
    static Histogram histogram;
    static List<ImageRegion> regions = new ArrayList<ImageRegion>();
    
    public static void setSourceBitmap(Bitmap bitmap)
	{
		Log.v("ColonyCount", "Heap.setSourceBitmap()");
		sourceBitmap = bitmap;
		System.gc();
	}

    public static Bitmap getSourceBitmap()
	{
		return sourceBitmap;
	}
	
    public static void freeSourceBitmap()
	{
		Log.v("ColonyCount", "Heap.freeSourceBitmap()");
		if(sourceBitmap != null)
		{
			sourceBitmap.recycle();
			sourceBitmap = null;
		}
		System.gc();
	}
    
    public static void setLumaMap(Image8 map)
	{
		Log.v("ColonyCount", "Heap.setLumaMap()");
		lumaMap = map;
		System.gc();
	}

    public static Image8 getLumaMap()
	{
		return lumaMap;
	}
	
    public static void freeLumaMap()
	{
		Log.v("ColonyCount", "Heap.freeLumaMap()");
		lumaMap = null;
		System.gc();
	}
	
    public static void setLumaBitmap(Bitmap bitmap)
	{
		Log.v("ColonyCount", "Heap.setLumaBitmap()");
		lumaBitmap = bitmap;
		System.gc();
	}
	
    public static Bitmap getLumaBitmap()
	{
		return lumaBitmap;
	}
	
    public static void freeLumaBitmap()
	{
		Log.v("ColonyCount", "Heap.freeLumaBitmap()");
		if(lumaBitmap != null)
		{
			lumaBitmap.recycle();
			lumaBitmap = null;
		}
		System.gc();	
	}
	
    public static void setHistogram(Histogram histogram)
	{
		Log.v("ColonyCount", "Heap.setHistogram()");
		ColonyCountHeap.histogram = histogram;
	}
	
    public static Histogram getHistogram()
	{
		return histogram;
	}
	
    public static void freeHistogram()
	{
		Log.v("ColonyCount", "Heap.freeHistogram()");
		histogram = null;
		System.gc();	
	}
    
    public static List<ImageRegion> getRegions()
    {
    	return regions;
    }
    
    public static void logHeapState()
    {
    	Log.v("ColonyCount", "Heap.logHeapState()");
    	if(sourceBitmap != null) Log.v("ColonyCount", "   sourceBitmap");	
    	if(lumaMap != null) Log.v("ColonyCount", "   lumaMap");	
    	if(lumaBitmap != null) Log.v("ColonyCount", "   lumaBitmap");	
    	if(histogram != null) Log.v("ColonyCount", "   histogram");	
    	if(regions.size() > 0) Log.v("ColonyCount", "   regions. Count:" + regions.size());	
    }
}